Skip to content

[OpenTelemetry] Drop non-finite values from histogram aggregations - #7759

Draft
martincostello wants to merge 26 commits into
open-telemetry:mainfrom
martincostello:drop-nonfinite-from-views
Draft

martincostello wants to merge 26 commits into
open-telemetry:mainfrom
martincostello:drop-nonfinite-from-views

Conversation

@martincostello

Copy link
Copy Markdown
Member

Changes

Non-finite values are no longer included in histograms to avoid permanently poisoning cumulative histogram aggregations.

From the metrics specification:

Implementations SHOULD NOT incorporate non-normal values (i.e., +Inf, -Inf, and NaNs) into the sum, min, and max fields, because these values do not map into a valid bucket.

This was found from a scan of the repository using Claude Code - it seems correct to me given the above, unless there's some nuance I've missed.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

Non-finite values are no longer included in histograms to avoid permanently poisoning cumulative histogram aggregations.
@codecov

codecov Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.10%. Comparing base (1e88560) to head (3a74d3c).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7759      +/-   ##
==========================================
+ Coverage   93.09%   93.10%   +0.01%     
==========================================
  Files         397      399       +2     
  Lines       23335    23604     +269     
  Branches     4359     4406      +47     
==========================================
+ Hits        21724    21977     +253     
- Misses       1103     1108       +5     
- Partials      508      519      +11     
Flag Coverage Δ
unittests-Project-Experimental 93.22% <100.00%> (+0.01%) ⬆️
unittests-Project-Stable 93.19% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/OpenTelemetry/Metrics/AggregatorStore.cs 91.25% <100.00%> (+0.34%) ⬆️
...c/OpenTelemetry/Metrics/MetricPoint/MetricPoint.cs 91.80% <100.00%> (+0.71%) ⬆️

... and 8 files with indirect coverage changes

@github-actions github-actions Bot added pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package labels Sep 15, 2026
Comment thread src/OpenTelemetry/CHANGELOG.md Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Filtering occurs after tagged metric-point allocation, allowing invalid measurements to consume cardinality and affect valid streams.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Updates histogram aggregation to drop non-finite measurements before aggregation.

Changes:

  • Filters NaN and infinities from histogram updates.
  • Adds regression coverage and updates Prometheus snapshots.
  • Documents the behavior change.
File summaries
File Description
src/OpenTelemetry/Metrics/MetricPoint/MetricPoint.cs Filters non-finite histogram values.
src/OpenTelemetry/CHANGELOG.md Documents the behavior change.
test/OpenTelemetry.Tests/Metrics/AggregatorTests.cs Adds cumulative histogram coverage.
test/OpenTelemetry.Tests/Metrics/MetricTestData.cs Updates min/max expectations.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.HistogramNaN.verified.txt Updates NaN output snapshot.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.HistogramInfinities.verified.txt Updates infinity output snapshot.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-10-28 13:24 UTC

Move out of draft to request review.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

- Do not consume cardinality slots for histograms when updating if only non-finite values.
- Add missing test coverage.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new test uses a banned constructor and removes coverage for streams containing only non-finite measurements.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Add missing test coverage.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation consistently filters invalid measurements before allocation and aggregation, with comprehensive regression coverage.

Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@martincostello
martincostello marked this pull request as ready for review September 17, 2026 11:54
@martincostello
martincostello requested a review from a team as a code owner September 17, 2026 11:54
@github-actions

Copy link
Copy Markdown
Contributor

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions Bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Sep 26, 2026
@martincostello martincostello added keep-open Prevents issues and pull requests being closed as stale and removed Stale Issues and pull requests which have been flagged for closing due to inactivity labels Sep 26, 2026
@Kielek

Kielek commented Oct 7, 2026

Copy link
Copy Markdown
Member

I have created open-telemetry/opentelemetry-specification#5346

If you want to merge this PR shortly, I would suggest to narrow changes to the exponential histograms only. We can extend this, when we have clarification from spec team.

@martincostello

Copy link
Copy Markdown
Member Author

If you want to merge this PR shortly

No rush on merge, I just wanted some opinions on whether the changes were right with regards to the spec or not.

Can wait on the outcome of open-telemetry/opentelemetry-specification#5346.

@martincostello
martincostello marked this pull request as draft October 8, 2026 09:11
@martincostello

Copy link
Copy Markdown
Member Author

Moving to draft until open-telemetry/opentelemetry-specification#5346 is resolved.

@martincostello martincostello added needs-spec-change Issues which require the OpenTelemetry Specification to clarify or define behavior spec-compliance Issues related to compliance with the OpenTelemetry Specification labels Oct 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The exponential histogram comments incorrectly call negative values undefined and should instead describe them as rejected by this SDK path without changing the existing guard.

1 open issue
2 resolved since last review

Review effort: Balanced

Update comment to be more accurate.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Maintainer confirmation is needed because the cited non-finite-value guidance covers exponential histograms, while dropping explicit-histogram counts and bucket observations would broaden SDK policy.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

keep-open Prevents issues and pull requests being closed as stale needs-spec-change Issues which require the OpenTelemetry Specification to clarify or define behavior pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package spec-compliance Issues related to compliance with the OpenTelemetry Specification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants